<template>
    <el-header class="header">
        <div class="l-content">
            <!-- 图标的展示 -->
            <el-button size="small" class="btn" @click="handerClick">
                 <el-icon :size="20"> <Menu/> </el-icon>
            </el-button>
            <!-- 面包屑 -->
            <el-breadcrumb separator="/" class="bread">
                <el-breadcrumb-item :to="{ path: '/' }" @click="bStore.curPage=null">首页</el-breadcrumb-item>
                <el-breadcrumb-item :to="bStore.curPage.path" v-if="bStore.curPage">{{bStore.curPage.label}}</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="r-content">
            <el-dropdown>
                <span class="el-dropdown-link">
                    <!-- <img class="user" :src="getImgSrc('swimmer')" alt=""> -->
                    <img class="user" :src="userFace" alt="">
                </span>
                <template #dropdown>
                    <el-dropdown-menu>
                        <el-dropdown-item @click="goUser">个人中心</el-dropdown-item>
                        <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </template>
            </el-dropdown>
        </div>
    </el-header>
</template>

<script setup>
// import { onUnmounted,onMounted } from 'vue';
import { explore,breadCum,userStore  } from '../store/index'
import { useRouter } from 'vue-router';
const router = useRouter()
const bStore = breadCum()
const uStore = userStore()
const exploreStore = explore()
// 动态引入图片，类似路由懒加载
// const getImgSrc = (name) =>{
//     //import.meta.url 表示当前路径，用来给第一个参数做相对路径的参考
//     return new URL(`../assets/user/${name}.jpg`,import.meta.url).href
// }

const userFace = JSON.parse(sessionStorage.getItem('userInfo'))?.face || ''
const handerClick = () =>{
    exploreStore.exploreStatus = !exploreStore.exploreStatus
    console.log('handerClick',exploreStore.exploreStatus);
}

const goUser = () =>{
    router.push('/user/center')

    const item = {
        name:'userCenter',
        label:'个人中心'
    }
    bStore.setPage(item)
}

const logout = () =>{
    localStorage.clear();
    router.push('/login')
}





</script>

<style lang="less" scoped>
    .header {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: center;
        background-color: rgb(47, 142, 180);

        & > .l-content{
            display: flex;
            align-items: center;

            & > .btn{
                margin-right: 20px;
            }
            & > .text{
                color:white
            }

            .bread :deep span{
                color: rgb(31, 31, 31) !important;
                cursor: pointer !important;
            }
        }
    }
    .r-content .user{
        object-fit: cover;
        width: 40px;
        height: 40px;
        border-radius: 50%;
    }

    
</style>